package com.qianyu.project.service.impl;

import cn.hutool.core.date.DateUtil;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.LeaseContract;
import com.qianyu.project.entity.LeaseContractDetail;
import com.qianyu.project.mapper.LeaseContractDetailMapper;
import com.qianyu.project.mapper.LeaseContractMapper;
import com.qianyu.project.service.ILeaseContractDetailService;
import com.qianyu.project.service.ILeaseContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 租赁合同 服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-01-30
 */
@Service
public class LeaseContractServiceImpl extends ServiceImpl<LeaseContractMapper, LeaseContract> implements ILeaseContractService {

    @Autowired
    LeaseContractMapper leaseContractMapper;
    @Autowired
    ILeaseContractDetailService iLeaseContractDetailService;
    @Override
    public String getMaxid() {
        String maxid = leaseContractMapper.getMaxid();
        if(maxid == null){
            maxid = DateUtil.today().replaceAll("-", "") + "000";
        }
        return maxid;

    }

    @FlowBegin("lease_contract")
    @Override
    public Integer saveLease(@FlowEntry("id") LeaseContract leaseContract, List<LeaseContractDetail> leaseContractDetails) {
        leaseContract.setApproveStatus("1");
      leaseContractMapper.insert(leaseContract);

        iLeaseContractDetailService.saveBatch(leaseContractDetails);

        return 1;
    }
}
